package ufba.mata61.compilador.app;

import java.io.FileWriter;
import java.io.IOException;

import ufba.mata61.compilador.app.core.Parser;
import ufba.mata61.compilador.app.core.Scanner;
import ufba.mata61.compilador.app.core.com.IToken;

/**
 * The main class
 * 
 * @author Joao Pedro Bittencourt
 *
 */
public class Compiler {
	
	private Scanner scanner;
	private Parser parser; 
	
	public Compiler(String sourceCode) {
		scanner = new Scanner(sourceCode);
	}
	
	public void init(){
		String token;
		String file = "";
		
		do{
			token = scanner.scan();
//			System.out.println("token: "+token);
			file += token+"\r\n"; 
//			   try {
//					Thread.sleep(1000);
//				} catch (InterruptedException e) {
//					e.printStackTrace();
//				}
		}
		while (!token.equals(IToken.EOF));
		
		String temp = "C:\\Users\\Johhny\\Desktop\\temp.token";
		FileWriter fw;
		try {
			fw = new FileWriter(temp);
			fw.write(file);
			fw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		parser = new Parser(temp);
		parser.start();
			
	}
	
	public static void main(String[] args){
		String file = "C:\\Users\\Johhny\\Desktop\\hello.lua";
		new Compiler(file).init();
	}
	

}
